package com.atguigu.service.impl;

import com.atguigu.dao.NginxServiceConfigPhpDao;
import com.atguigu.dao.impl.NginxServiceConfigPhpDaoImpl;
import com.atguigu.pojo.NginxServiceConfigPhp;
import com.atguigu.pojo.Page;
import com.atguigu.service.NginxServiceConfigPhpService;

import java.util.List;

public class NginxServiceConfigPhpServiceImpl implements NginxServiceConfigPhpService {
    NginxServiceConfigPhpDao nginxServiceConfigPhpDao=new NginxServiceConfigPhpDaoImpl();
    @Override
    public void addNginxServiceConfigPhp(NginxServiceConfigPhp nginxServiceConfigPhp) {
        nginxServiceConfigPhpDao.addNginxServiceConfigPhp(nginxServiceConfigPhp);
    }

    @Override
    public void updateNginxServiceConfigPhp(NginxServiceConfigPhp nginxServiceConfigPhp) {
        nginxServiceConfigPhpDao.updateNginxServiceConfigPhp(nginxServiceConfigPhp);
    }

    @Override
    public void deleteNginxServiceConfigPhpById(String id) {
        nginxServiceConfigPhpDao.deleteNginxServiceConfigPhpById(id);
    }

    @Override
    public NginxServiceConfigPhp queryNginxServiceConfigPhpById(String id) {
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhpById(id);
    }

    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhps() {
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhps();
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByServiceId(String serviceId){
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhpsByServiceId(serviceId);
    }

    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByPort(String port){
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhpsByPort(port);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByServiceIdDomainPort(String serviceId,String domain,String port){
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhpsByServiceIdDomainPort(serviceId,domain,port);
    }

    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByProjectModuleId(String projectModuleId){
        return nginxServiceConfigPhpDao.queryNginxServiceConfigPhpsByProjectModuleId(projectModuleId);
    }

    @Override
    public Page page(Integer pageNo, Integer pageSize) {
        Page<NginxServiceConfigPhp> page=new Page<>();
        page.setPagesize(pageSize);
        Integer pageTotalCount=nginxServiceConfigPhpDao.queryForPageTotalCount();
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal=pageTotalCount/pageSize;
        if(pageTotalCount % pageSize >0){
            pageTotal++;//总条数,除以一页条数,大于0,页码数+1
        }
        page.setPageTotal(pageTotal);
        System.out.println("pageNo 原来是 is:"+pageNo);
        if(pageNo<1){//防止用户输入量太大
            pageNo=1;
        }else if(pageNo>pageTotal){
            pageNo=pageTotal;
        }
        page.setPageNo(pageNo);//当前页码
        System.out.println("pageNo 现在是 is:"+pageNo);
        System.out.println("pageTotal is:"+pageTotal);
        //要得到的是page的items
        Integer begin=(page.getPageNo()-1)*pageSize;
        List<NginxServiceConfigPhp> items=nginxServiceConfigPhpDao.queryForPageItems(begin,pageSize);
        page.setItems(items);
        return page;
    }
}
